package com.hxd.otc.module.fiat_deal.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.fiat_deal.bean.DealTeamBean;
import com.hxd.otc.module.fiat_deal.contract.DealContract;
import com.hxd.otc.module.fiat_deal.model.DealModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.utils.StringUtil;

import java.util.ArrayList;
import java.util.TreeSet;

/**
 * Created by lzy on 2018/9/15 0015.
 * description ${交易Presenter}
 */
public class DealPresenter extends BasePresenter<DealContract.IView> implements DealContract.IPresenter {

    DealModel model;
    private ArrayList<DealTeamBean> mDealTeamBeans;
    private ArrayList<String> mFiats = new ArrayList<>();

    private String mFiat = "CNY";
    private String mBankTypeValue = "";


    public DealPresenter(DealContract.IView iView) {
        super(iView);
        model = new DealModel();
    }

    @Override
    public void getDealTeam() {
        model.getCoinType(new BaseObserver<ArrayList<DealTeamBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<DealTeamBean> dealTeamBeans) {
                mDealTeamBeans = dealTeamBeans;
                mFiats.clear();
                TreeSet<String> fiats = new TreeSet<>();
                for (DealTeamBean dealTeamBean : mDealTeamBeans) {
                    fiats.addAll(dealTeamBean.getFiatsSet());
                }
                mFiats.addAll(fiats);
                mView.gainDealTeamSuccess();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.gainDealTeamFail(errMessage);
            }

        }, mView.<BaseBean<ArrayList<DealTeamBean>>>bindAutoDispose());
    }

    @Override
    public ArrayList<DealTeamBean> getAllDealTeamBeans(){
        return mDealTeamBeans;
    }


    @Override
    public String getFiat() {
        return mFiat;
    }
    @Override
    public void setFiat(String fiat) {
        mFiat = fiat;
    }

    public ArrayList<String> getFiats() {
        return mFiats;
    }

    @Override
    public void setBankTypeValue(String bankTypeValue) {
        mBankTypeValue = StringUtil.emptyIfNull(bankTypeValue);
    }

    @Override
    public String getBankTypeValue() {
        return StringUtil.emptyIfNull(mBankTypeValue);
    }
}
